/*     */ package com.wgcloud.controller;
/*     */ 
/*     */ import cn.hutool.json.JSONObject;
/*     */ import cn.hutool.json.JSONUtil;
/*     */ import com.github.pagehelper.PageInfo;
/*     */ import com.wgcloud.entity.DockerInfo;
/*     */ import com.wgcloud.entity.DockerState;
/*     */ import com.wgcloud.entity.SystemInfo;
/*     */ import com.wgcloud.service.DashboardService;
/*     */ import com.wgcloud.service.DockerInfoService;
/*     */ import com.wgcloud.service.DockerStateService;
/*     */ import com.wgcloud.service.ExcelExportService;
/*     */ import com.wgcloud.service.HostGroupService;
/*     */ import com.wgcloud.service.LogInfoService;
/*     */ import com.wgcloud.service.SystemInfoService;
/*     */ import com.wgcloud.util.DateUtil;
/*     */ import com.wgcloud.util.HostUtil;
/*     */ import com.wgcloud.util.PageUtil;
/*     */ import com.wgcloud.util.ResDataUtils;
/*     */ import com.wgcloud.util.TokenUtils;
/*     */ import com.wgcloud.util.license.LicenseUtil;
/*     */ import com.wgcloud.util.staticvar.StaticKeys;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.annotation.Resource;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.ui.Model;
/*     */ import org.springframework.web.bind.annotation.RequestBody;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/dockerInfo"})
/*     */ public class DockerInfoController
/*     */ {
/*  44 */   private static final Logger logger = LoggerFactory.getLogger(com.wgcloud.controller.DockerInfoController.class);
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private DockerInfoService dockerInfoService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private DockerStateService dockerStateService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private LogInfoService logInfoService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private DashboardService dashBoardService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private SystemInfoService systemInfoService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private HostGroupService hostInfoService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private DashboardService dashboardService;
/*     */   
/*     */   @Resource
/*     */   private ExcelExportService excelExportService;
/*     */   
/*     */   @Autowired
/*     */   private TokenUtils tokenUtils;
/*     */ 
/*     */   
/*     */   @ResponseBody
/*     */   @RequestMapping({"agentList"})
/*     */   public String agentList(@RequestBody String paramBean) {
/*  84 */     JSONObject agentJsonObject = (JSONObject)JSONUtil.parse(paramBean);
/*  85 */     if (!this.tokenUtils.checkAgentToken(agentJsonObject)) {
/*  86 */       logger.error("token is error");
/*  87 */       return ResDataUtils.resetErrorJson("token is error");
/*     */     } 
/*  89 */     Map<String, Object> params = new HashMap<>();
/*  90 */     if (null == agentJsonObject.get("hostname") || StringUtils.isEmpty(agentJsonObject.get("hostname").toString())) {
/*  91 */       return "";
/*     */     }
/*  93 */     params.put("hostname", agentJsonObject.get("hostname").toString());
/*     */     try {
/*  95 */       params.put("active", "1");
/*  96 */       List<DockerInfo> DockerInfoList = this.dockerInfoService.selectAllByParams(params);
/*  97 */       return ResDataUtils.resetSuccessJson(DockerInfoList);
/*  98 */     } catch (Exception e) {
/*  99 */       logger.error("agent获取docker信息错误", e);
/* 100 */       this.logInfoService.save("agent获取docker信息错误", e.toString(), "1");
/* 101 */       return ResDataUtils.resetErrorJson(e.toString());
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"list"})
/*     */   public String DockerInfoList(DockerInfo dockerInfo, Model model, HttpServletRequest request) {
/* 114 */     Map<String, Object> params = new HashMap<>();
/*     */     
/*     */     try {
/* 117 */       LicenseUtil.maxLicense_10(model, request);
/*     */ 
/*     */       
/* 120 */       StringBuffer url = new StringBuffer();
/* 121 */       String hostname = null;
/* 122 */       if (!StringUtils.isEmpty(dockerInfo.getHostname())) {
/* 123 */         hostname = dockerInfo.getHostname();
/* 124 */         params.put("hostname", hostname.trim());
/* 125 */         url.append("&hostname=").append(hostname);
/*     */       } 
/* 127 */       if (!StringUtils.isEmpty(dockerInfo.getState())) {
/* 128 */         params.put("state", dockerInfo.getState());
/* 129 */         url.append("&state=").append(dockerInfo.getState());
/*     */       } 
/* 131 */       PageInfo<DockerInfo> pageInfo = this.dockerInfoService.selectByParams(params, dockerInfo.getPage().intValue(), dockerInfo.getPageSize().intValue());
/* 132 */       for (DockerInfo dockerInfo1 : pageInfo.getList()) {
/* 133 */         dockerInfo1.setHostname(dockerInfo1.getHostname() + HostUtil.addRemark(dockerInfo1.getHostname()));
/*     */       }
/* 135 */       PageUtil.initPageNumber(pageInfo, model);
/* 136 */       model.addAttribute("pageUrl", "/dockerInfo/list?1=1" + url.toString());
/* 137 */       model.addAttribute("page", pageInfo);
/* 138 */       model.addAttribute("DockerInfo", dockerInfo);
/* 139 */     } catch (Exception e) {
/* 140 */       logger.error("查询docker信息错误", e);
/* 141 */       this.logInfoService.save("查询docker信息错误", e.toString(), "1");
/*     */     } 
/*     */     
/* 144 */     return "docker/list";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"save"})
/*     */   public String saveDockerInfo(DockerInfo dockerInfo, Model model, HttpServletRequest request) {
/* 158 */     String errorMsg = "保存docker信息错误";
/*     */     try {
/* 160 */       if (StringUtils.isEmpty(dockerInfo.getId())) {
/* 161 */         this.dockerInfoService.save(dockerInfo);
/*     */       } else {
/* 163 */         this.dockerInfoService.updateById(dockerInfo);
/*     */       } 
/* 165 */     } catch (Exception e) {
/* 166 */       logger.error(errorMsg, e);
/* 167 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 169 */     return "redirect:/dockerInfo/list";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"saveBatch"})
/*     */   public String saveBatchDockerInfo(DockerInfo dockerInfo, Model model, HttpServletRequest request) {
/* 182 */     String errorMsg = "批量保存docker信息错误";
/*     */     try {
/* 184 */       String[] hostnames = request.getParameterValues("hostnames");
/* 185 */       if (null == hostnames || hostnames.length < 1) {
/* 186 */         return "redirect:/dockerInfo/list";
/*     */       }
/* 188 */       for (String selectedHost : hostnames) {
/* 189 */         dockerInfo.setHostname(selectedHost);
/* 190 */         this.dockerInfoService.save(dockerInfo);
/*     */       } 
/* 192 */     } catch (Exception e) {
/* 193 */       logger.error(errorMsg, e);
/* 194 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 196 */     return "redirect:/dockerInfo/list";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"edit"})
/*     */   public String edit(Model model, HttpServletRequest request) {
/* 208 */     String errorMsg = "添加docker信息";
/* 209 */     String id = request.getParameter("id");
/* 210 */     DockerInfo DockerInfo = new DockerInfo();
/*     */     try {
/* 212 */       List<SystemInfo> systemInfoList = this.systemInfoService.selectAllByParams(new HashMap<>());
/* 213 */       model.addAttribute("systemInfoList", systemInfoList);
/* 214 */       if (StringUtils.isEmpty(id)) {
/* 215 */         model.addAttribute("dockerInfo", DockerInfo);
/*     */ 
/*     */         
/* 218 */         Map<String, Object> params = new HashMap<>();
/* 219 */         int dbSize = this.dockerInfoService.countByParams(params);
/* 220 */         if (dbSize >= 10 && !StaticKeys.LICENSE_STATE.equals("1")) {
/* 221 */           return "redirect:/dockerInfo/list?liceFlage=1";
/*     */         }
/*     */ 
/*     */ 
/*     */         
/* 226 */         return "docker/add";
/*     */       } 
/* 228 */       DockerInfo = this.dockerInfoService.selectById(id);
/* 229 */       model.addAttribute("dockerInfo", DockerInfo);
/* 230 */     } catch (Exception e) {
/* 231 */       logger.error(errorMsg, e);
/* 232 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 234 */     return "docker/add";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"editBatch"})
/*     */   public String editBatch(Model model, HttpServletRequest request) {
/* 246 */     String errorMsg = "批量添加docker信息";
/* 247 */     DockerInfo DockerInfo = new DockerInfo();
/*     */     try {
/* 249 */       List<SystemInfo> systemInfoList = this.systemInfoService.selectAllByParams(new HashMap<>());
/* 250 */       model.addAttribute("systemInfoList", systemInfoList);
/* 251 */       model.addAttribute("dockerInfo", DockerInfo);
/*     */ 
/*     */       
/* 254 */       Map<String, Object> params = new HashMap<>();
/* 255 */       int dbSize = this.dockerInfoService.countByParams(params);
/* 256 */       if (dbSize >= 10 && !StaticKeys.LICENSE_STATE.equals("1")) {
/* 257 */         return "redirect:/dockerInfo/list?liceFlage=1";
/*     */       
/*     */       }
/*     */     }
/* 261 */     catch (Exception e) {
/* 262 */       logger.error(errorMsg, e);
/* 263 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 265 */     return "docker/addBatch";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"view"})
/*     */   public String viewChart(Model model, HttpServletRequest request) {
/* 278 */     String errorMsg = "查看docker信息统计图错误";
/* 279 */     String id = request.getParameter("id");
/* 280 */     String date = request.getParameter("date");
/* 281 */     String am = request.getParameter("am");
/* 282 */     DockerInfo DockerInfo = new DockerInfo();
/*     */     try {
/* 284 */       DockerInfo = this.dockerInfoService.selectById(id);
/* 285 */       Map<String, Object> params = new HashMap<>();
/* 286 */       if (StringUtils.isEmpty(date)) {
/* 287 */         date = DateUtil.getCurrentDate();
/* 288 */         am = this.dashboardService.getDefaultAm();
/*     */       } 
/* 290 */       this.dashboardService.setDateParam(am, date, params);
/* 291 */       model.addAttribute("datenow", date);
/* 292 */       model.addAttribute("am", am);
/* 293 */       model.addAttribute("dateList", this.dashboardService.getDateList());
/* 294 */       model.addAttribute("amList", this.dashboardService.getAmList());
/* 295 */       params.put("dockerInfoId", DockerInfo.getId());
/* 296 */       model.addAttribute("dockerInfo", DockerInfo);
/* 297 */       List<DockerState> DockerStateList = this.dockerStateService.selectAllByParams(params);
/* 298 */       model.addAttribute("dockerStateList", JSONUtil.parseArray(DockerStateList));
/* 299 */     } catch (Exception e) {
/* 300 */       logger.error(errorMsg, e);
/* 301 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 303 */     return "docker/view";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"chartExcel"})
/*     */   public void chartExcel(Model model, HttpServletRequest request, HttpServletResponse response) {
/* 315 */     String errorMsg = "docker信息统计图导出excel";
/* 316 */     String id = request.getParameter("id");
/* 317 */     String date = request.getParameter("date");
/* 318 */     String am = request.getParameter("am");
/*     */     try {
/* 320 */       if (!StaticKeys.LICENSE_STATE.equals("1")) {
/* 321 */         response.setContentType("text/html;charset=UTF-8");
/* 322 */         response.getOutputStream().write("The excel needs to wgcloud-pro version".getBytes());
/*     */         return;
/*     */       } 
/* 325 */       if (StringUtils.isEmpty(id)) {
/* 326 */         response.setContentType("text/html;charset=UTF-8");
/* 327 */         response.getOutputStream().write("The excel must  require parameters".getBytes());
/*     */         return;
/*     */       } 
/* 330 */       Map<String, Object> params = new HashMap<>();
/* 331 */       if (StringUtils.isEmpty(date)) {
/* 332 */         date = DateUtil.getCurrentDate();
/* 333 */         am = this.dashboardService.getDefaultAm();
/*     */       } 
/* 335 */       params.put("dockerInfoId", id);
/* 336 */       this.dashboardService.setDateParam(am, date, params);
/* 337 */       this.excelExportService.exportDockerExcel(params, response);
/* 338 */     } catch (Exception e) {
/* 339 */       logger.error(errorMsg, e);
/* 340 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"del"})
/*     */   public String delete(Model model, HttpServletRequest request, RedirectAttributes redirectAttributes) {
/* 356 */     String errorMsg = "删除docker信息错误";
/* 357 */     DockerInfo DockerInfo = new DockerInfo();
/*     */     try {
/* 359 */       if (!StringUtils.isEmpty(request.getParameter("id"))) {
/* 360 */         String[] ids = request.getParameter("id").split(",");
/* 361 */         for (String id : ids) {
/* 362 */           DockerInfo = this.dockerInfoService.selectById(id);
/* 363 */           this.logInfoService.save("删除docker信息：" + DockerInfo.getHostname(), "删除docker信息：" + DockerInfo.getHostname() + "：" + DockerInfo.getDockerId(), "0");
/*     */         } 
/* 365 */         this.dockerInfoService.deleteById(ids);
/*     */       } 
/* 367 */     } catch (Exception e) {
/* 368 */       logger.error(errorMsg, e);
/* 369 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/*     */     
/* 372 */     return "redirect:/dockerInfo/list";
/*     */   }
/*     */ }


/* Location:              /Users/zhangyongxin/soft-install/wgcloud/wgcloud-v3.3.5/server/bank/wgcloud-server-release.jar!/BOOT-INF/classes/com/wgcloud/controller/DockerInfoController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */